import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'

import store from '@/store'

import routes from './routes'
const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})


// router.beforeEach((to, from, next) => {
//   if (to.meta?.title) {
//     document.title = to.meta.title as string
//   }

//   next()
// })

router.beforeEach((to, from, next) => {

  if (to.path !== '/login' && !store.state.user.id) {

    next('/login')
  }
  else {
    next()
  }

})

export default router
